package com.zpark;

import com.zpark.service.IUserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

// 开启测试主类注解
@SpringBootTest
public class ImportSpringConfigApplicationText {

    @Autowired
    private IUserService userService;

    // 自动注入Spring容器对象
    @Autowired
    private ApplicationContext aco;

    @Test  // 让这个方法单独执行
    public void test(){
        System.out.println("测试类正常执行");
    }

    @Test
    public void userServiceTest(){
        // 判断某一个bean对象是否存在spring容器当中
        boolean flag = aco.containsBean("userserviceimpl");

        if (flag) {
            System.out.println("容器当中存在:userServiceImpl对象");
        }else{
            System.out.println("容器当中不存在:userServiceImpl对象");
        }
    }

    @Test
    public void userServiceTest02(){
        // 判断某一个bean对象是否存在spring容器当中
        boolean flag = aco.containsBean("userService");

        if (flag) {
            System.out.println("容器当中存在:userService对象");
        }else{
            System.out.println("容器当中不存在:userService对象");
        }
    }
}
